$(function () {

    $("#pandian1").keyup(function () {
        console.log('123');

        var name = $("#pandian1").val();
        $.ajax({
            url: "getCustomerName.do",
            data: "name=" + name,
            success: function (data) {
                console.log(JSON.stringify(data));

                // $("#pandiandiv1").html("");
                //
                // for (var i = 0; i < data.length; i++) {
                //     $("#pandiandiv1").append("<div>"+data[i].custId+"</div>");
                // }
                $("#d1").html("");
                if (name != "") {
                    $("#d1").attr("hidden", false);
                    $("#d1").append("<table border='1px' id='t1'><tr><td>客户ID&nbsp&nbsp&nbsp&nbsp</td><td>客户名称&nbsp&nbsp&nbsp&nbsp</td><td>客户手机&nbsp&nbsp&nbsp&nbsp</td><td>客户电话&nbsp&nbsp&nbsp&nbsp</td></tr></table>")
                    for (var i = 0; i < data.length; i++) {
                        $("#t1").append("<tr onclick='xiuGai(this)'  onmouseover='changeDivBC(this)' onmouseout='changeDiv2(this)'><td>" + data[i].custID + "</td><td>" + data[i].custName + "</td><td>" + data[i].custMobile + "</td><td>" + data[i].custTel + "</td></tr>")
                    }
                } else {
                    $("#d1").attr("hidden", true);

                }

            }
        })

    })

    $("#form1").submit(function () {

        var date1 = $("#date1").val();
        var date2 = $("#date2").val();
        if (date1 > date2) {
            alert('开始日期不能大于结束日期');
            return false;
        } else {
            // alert('合格');
            return true;
        }
    })


})


function changeDivBC(div2) {
    // div2.style.backgroundColor = "red";
    div2.style.backgroundColor = "pink";
}

function xiuGai(div1) {

    //获取得到需要的值
    var want = div1.cells[2].innerHTML + ":" + div1.cells[1].innerHTML;

    var want1 = div1.cells[0].innerHTML;


    //2 输入框的内容是你点击的div的内容
    $("#pandian1").val(want);

    $("#pandian3").val(want1);

    //1 让下方div内容清空
    $("#d1").html("");
}

function changeDiv2(div2) {
    div2.style.backgroundColor = "white";
}